package com.itheima.mall.api.oms;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.itheima.mall.mapper.oms.ReturnApplyMapper;
import com.itheima.mall.pojo.oms.OmsOrderReturnApply;
import com.itheima.mall.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class ReturnApplyApiImpl implements ReturnApplyApi{
    @Autowired
    private ReturnApplyMapper returnApplyMapper;

    @Override
    public void deleteApplyByIds(Integer[] ids) {
        for (Integer id : ids) {
            Long orderReturnApplyId = Convert.toLong(id);
            LambdaQueryWrapper<OmsOrderReturnApply> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(OmsOrderReturnApply::getId,orderReturnApplyId);
            returnApplyMapper.delete(wrapper);
        }

    }

    @Override
    public PageResult ReturnApply(String createTime, String handleMan, String handleTime, Integer id, Integer pageNum, Integer pageSize, String receiverKeyword, Integer status) {
        Page pageCondition = new Page(pageNum,pageSize);
        LambdaQueryWrapper<OmsOrderReturnApply> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(id),OmsOrderReturnApply::getId,id);
        Page pageR = returnApplyMapper.selectPage(pageCondition, lqw);
        PageResult pageResult = new PageResult();
        pageResult.setList(pageR.getRecords());
        pageResult.setPageSize(pageSize);
        pageResult.setPageNum(pageNum);
        pageResult.setTotalPage(Convert.toInt(pageR.getPages()));
        pageResult.setTotal(Convert.toInt(pageR.getTotal()));
        return pageResult;


    }

    @Override
    public void updateStatus(OmsOrderReturnApply omsOrderReturnApply) {
        returnApplyMapper.updateById(omsOrderReturnApply);
    }

    @Override
    public OmsOrderReturnApply getReturnApply(Integer id) {
        return returnApplyMapper.selectById(id);
    }
}


